<style lang="scss" scoped>
@import "@/assets/css/variable";
.activityShow {
  width: 100%;
  padding-bottom: 6.2rem;
  background-color: #f2f2f2;
  min-height: 100%;
  font-size: 1.2rem;
  box-sizing: border-box;
  position: relative;
  flex: 1;
  // overflow: hidden;
  $radiusSize: 100%;
  display: flex;
  flex-direction: column;
  padding: 4rem 1rem 0 ;
  .my_tuan {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3rem;
    z-index: 2;
    // background: -webkit-linear-gradient(top, #fd8701, #fd8701);
    line-height: 3rem;
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #fff;
    .icon {
      position: absolute;
      top: 50%;
      left: 10px;
      transform: translateY(-50%);
    }
  }
    .conter {
      display: flex;
      justify-content: center;
      box-sizing: border-box;
      flex-direction: column;
      width: 100%;
      height: 5rem; 
      background-color: #fff6e4;
      box-shadow:0px 3px 3px rgba(0, 0, 0, 0.2);
      border-radius: 8px;
      margin-bottom: 1rem;
      .num {
        width: 10%;
        height: 100%;
        line-height: 5rem;
        text-align: center;
        color: #f1c01b;
      }
      .timer {
        padding: 1rem 1rem;
        color: #999999;
      }
      .middle {
        display: flex;
        align-items: center;
        .middle_left {
          overflow: hidden;
          width: 3.8rem;
          height: 3.8rem;
          border-radius: 3.8rem;
          margin-right: 1rem;
        }
        img {
          width: 100%;
          height: 100%;
        }
        .middle_right {
          display: flex;
          justify-content: space-between;
          width: 70%;
          margin: .5rem 1rem;
          span {
              margin-right: 10px;
              color: #aeaeae;
          }
        }
      }
    }
    .van_field {
    box-sizing: border-box;
    margin-bottom: 10px;
    box-shadow:0px 3px 3px rgba(0, 0, 0, 0.2);
    height: 4rem;
    font-size: 1.2rem;
    display: flex;
    justify-content: space-between;
    line-height: 4rem;
    padding-left: 10px;
    color: #323233;
    background-color: #fff;
    .van-radio--horizontal {
      margin-right: 7px;
    }
  }
  }
  
</style>
<template>
  <div class="activityShow">
    <div class="my_tuan" :style="{ backgroundColor: theme_color }">
      <van-icon class="icon" name="arrow-left" @click="iconClick" />
      <span>排行榜</span>
    </div>
    <div
        class="van_field"
      >
          <span>类型</span>
          <van-radio-group
            v-model="status"
            direction="horizontal"
          >
            <van-radio name="1" @click="commissionClick">佣金</van-radio>
            <van-radio name="2" @click="envelopeClick">红包</van-radio>
          </van-radio-group>
       
    </div>
    <template v-if="rankingShow">
      <div class="conter" v-for="(item, index) in rankingList" :key="index">
        <div class="middle" >
          <span class="num">{{index+1}}</span>
          <div class="middle_left">
              <img :src="item.avatar" alt="">
          </div>
          <div class="middle_right">
              <span>用户名: {{item.name}}</span>
              <span>累积红包: {{item.gifts}} 元</span>
          </div>
        </div>
      </div>
    </template>
    <template v-if="commissionShow">
      <div class="conter" v-for="(item, index) in commissionList" :key="index">
        <div class="middle" >
          <span class="num">{{index+1}}</span>
          <div class="middle_left">
              <img :src="item.avatar" alt="">
          </div>
          <div class="middle_right">
              <span>用户名: {{item.name}}</span>
              <span>累积佣金: {{item.total}} 元</span>
          </div>
        </div>
      </div>
    </template>
    
    <Nodata v-show="nodataShow"></Nodata>
  </div>
</template>

<script>
import { Button, Toast, Tab, Tabs, Icon, Dialog, Popup, Field, RadioGroup, Radio } from "vant";
import Nodata from '@/components/Nodata'
// import QRCode from 'qrcode'
// import html2canvas from 'html2canvas'
// import func from 'vue-editor-bridge';
// import utils from '@/assets/js/utils.js'
export default {
  name: "activityShow",
  components: {
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [Button.name]: Button,
    [Icon.name]: Icon,
    [Dialog.name]: Dialog,
    [Popup.name]: Popup,
    [Field.name]: Field,
    [RadioGroup.name]: RadioGroup,
    [Radio.name]: Radio,
    Nodata
  },
  data() {
    return {
      openid: '',
      activity_id: null,
      status: '2',
      rankingList: [],
      commissionList: [],
      rankingShow: true,
      commissionShow: false,
      theme_color: '',
      nodataShow: false
    };
  },
  created() {
    const Item = JSON.parse(localStorage.getItem('OrderItem'))
    this.openid = localStorage.getItem("COPENID")
    this.activity_id = this.$route.query.activity_id
    this.theme_color = this.$route.hash
    // this.activity_id = Item.activityItem.activitys_id
    this.getGiftsRanking()
  },
  // computed: {
  //   getOpenId() {
  //     this.openid = this.$store.state.openid
  //     return this.openid
  //   }
  // },
  mounted() {
  },
  methods: {
    getGiftsRanking() {
      Toast.loading({
        message: '加载中...',
        forbidClick: true,
        loadingType: 'spinner',
        duration: 1000
      });
      let params = {openid: this.openid, activity_id: this.activity_id}
      this.$request.getGiftsRanking(params).then(res => {
        this.rankingList = res.data.data
        if(this.rankingList.length == 0) {
          this.nodataShow = true
        }
        console.log(this.rankingList);
      })
    },
    iconClick() {
      this.$router.go(-1)
    },
    palyclick() {

    },
    envelopeClick() {
      this.rankingShow = true
      this.commissionShow = false
      this.nodataShow = false
      this.getGiftsRanking()
    },
    commissionClick() {
      this.rankingShow = false
      this.commissionShow = true
      this.nodataShow = false
      Toast.loading({
        message: '加载中...',
        forbidClick: true,
        loadingType: 'spinner',
        duration: 1000
      });
      let params = {activity_id: this.activity_id}
      this.$request.getCommissionRanking(params).then(res => {
        this.commissionList = res.data.data
        if(this.commissionList.length == 0) {
          this.nodataShow = true
        }
        console.log(this.commissionList);
      })
    }
  },
};
</script>